<?php

class Template {
	
	/*
 * @the registry
 */
	private $registry;
	private $template;
	
	/*
 * @Variables array
 */
	private $vars = array ();
	
	function __construct($registry,$template) {
		$this->registry = $registry;
		$this->template = $template;
	
	}
	
	public function __set($index, $value) {
		$this->vars [$index] = $value;
	}
	
	//render page
	function render($name){
		$path = __SITE_PATH . '/layout/'.$name;
		include ($path);
	}
	
	function show(){
		$path = __SITE_PATH . '/layout/index.phtml';
		include ($path);
	}
	
	function showContent(){
		$this->showTemplate($this->template);
	}
	
	private function showTemplate($name) {
		//search view in the folder
		$path = __SITE_PATH . '/views' .  '/'. $name . '.phtml';
		
		if (file_exists ( $path ) == false) {
			throw new Exception ( 'Template not found in ' . $path );
			return false;
		}
		
		// Load variables
		foreach ( $this->vars as $key => $value ) {
			$$key = $value;
		}
		
		include ($path);
		
	}

}

?>
